package com.zhongkai.controller;

import com.zhongkai.app.service.AddressService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AddressController {


    @Autowired
    private AddressService addressService;

    @RequestMapping(value = "/address/province", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult address_province() {

        ZhongkaiResult province = addressService.getProvince();

        return province;
    }


    /**
     * 获取市
     *
     * @param province 省份id
     */
    @RequestMapping(value = "/address/city", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult address_city(String province) {

        ZhongkaiResult city = addressService.getCity(province);

        return city;
    }



    /**
     * 获取区
     *
     * @param city 市id
     */
    @RequestMapping(value = "/address/country", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult address_country(String city) {

        ZhongkaiResult cities = addressService.getCountry(city);

        return cities;
    }


    /**
     * 获取乡
     *
     * @param country 市id
     */
    @RequestMapping(value = "/address/town", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult address_town(String country) {

        ZhongkaiResult town = addressService.getTown(country);

        return town;
    }




    /**
     * 获取乡
     *
     * @param id
     */
    @RequestMapping(value = "/address", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getMyAddress(String id) {

        ZhongkaiResult town = addressService.getMyAddress(id);

        return town;
    }
}
